package com.embracesource.monitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.embracesource.monitor.entity.Product;
import com.embracesource.monitor.mapper.ProductMapper;
import com.embracesource.monitor.service.IProductService;
import com.gnerv.pabu.basic.core.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 基础平台-产品表 服务实现类
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019-09-18
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Resource
    private ProductMapper productMapper;

    @Override
    public boolean saveProduct(Product product) {
        if (StringUtils.isEmpty(product.getUkId())) {
            createProduct(product);
        } else {
            updateProduct(product);
        }
        return true;

    }

    @Override
    public boolean createProduct(Product product) {
        product.setUkId(UUIDUtils.getLower());
        productMapper.insert(product);
        return true;
    }

    @Override
    public boolean deleteProduct(String productId) {
        productMapper.deleteById(productId);
        return true;
    }

    @Override
    public boolean updateProduct(Product product) {
        productMapper.updateById(product);
        return true;
    }

    @Override
    public Product selectProduct(String productId) {
        Product product = productMapper.selectById(productId);
        return product;
    }

    @Override
    public Page<Product> listProduct(Product product, Long current, Long size) {
        Page<Product> products = productMapper.listProduct(new Page<>(current, size), product);
        return products;
    }
}
